<template>
  <div class="deliver-goods">
    <header>
      <div class="order-box">
        <div class="order-no">订单号：{{ formData.order_no }}</div>

      </div>
      <div class="name">
        <div>
          用户姓名：{{ ruleForm.user_name }}<span class="phone">用户电话：{{ ruleForm.user_tel }}</span>
        </div>
        <div>收货地址：{{ ruleForm.province }} {{ ruleForm.city }} {{ ruleForm.area }} {{ ruleForm.address }}</div>
      </div>
    </header>
    <div class="goods">
      <div> 产品：{{formData.store_name}} {{formData.spec_values ? formData.spec_values:'单规格'  }} </div>
      <div class="img-box"> 图片：<el-image :src="$imageFull(formData.image)" style="height: 80px" /> </div>
    </div>

    <el-form :model="formData" ref="formData" label-width="100px" class="demo-ruleForm">

      <div class="form-box">
        <el-form-item label="售后单号">
          <el-input v-model="formData.after_sales_no" readonly></el-input>
        </el-form-item>
        <el-form-item label="申请类型">
          <el-tag
            :type="APPLY_FOR_TYPE[String(formData.apply_for_type)] && APPLY_FOR_TYPE[String(formData.apply_for_type)].type"
            disable-transitions>
            <i :class="APPLY_FOR_TYPE[String(formData.apply_for_type)] && APPLY_FOR_TYPE[String(formData.apply_for_type)].icon"
              style="margin-right: 4px" />
            {{ APPLY_FOR_TYPE[String(formData.apply_for_type)] ? APPLY_FOR_TYPE[String(formData.apply_for_type)].text : '未知状态' }}
          </el-tag>
        </el-form-item>

        <el-form-item label="售后状态">
          <el-tag
            :type="STORE_ORDER_AFTER_SALES_STATUS[String(formData.status)] && STORE_ORDER_AFTER_SALES_STATUS[String(formData.status)].type"
            disable-transitions>
            <i :class="STORE_ORDER_AFTER_SALES_STATUS[String(formData.status)] && STORE_ORDER_AFTER_SALES_STATUS[String(formData.status)].icon"
              style="margin-right: 4px" />
            {{ STORE_ORDER_AFTER_SALES_STATUS[String(formData.status)] ? STORE_ORDER_AFTER_SALES_STATUS[String(formData.status)].text : '未知状态' }}
          </el-tag>
        </el-form-item>



        <el-form-item label="申请原因">
          <el-input v-model="formData.refund_explain" readonly></el-input>
        </el-form-item>

        <el-form-item label="退款金额">
          <el-input v-model="formData.refund_price" readonly></el-input>
        </el-form-item>
        <el-form-item label="联系电话">
          <el-input v-model="ruleForm.phone" readonly></el-input>
        </el-form-item>

        <el-form-item label="快递单号">
          <el-input v-model="formData.refund_express" readonly></el-input>
        </el-form-item>

        <el-form-item label="快递公司">
          <el-input v-model="formData.refund_express_name" readonly></el-input>
        </el-form-item>

        <el-form-item label="退货运费">
          <el-input v-model="formData.refund_express_prices" readonly></el-input>
        </el-form-item>

        <el-divider></el-divider>

        <el-form-item label="审核原因" prop="reason">
          <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入审核原因" v-model="formData.reason">
          </el-input>
        </el-form-item>
        <div class="def-bt-box" v-if="isShowButtons()">
          <el-button type="primary" @click="submitData(2)" class="bt-fix"> 通过 </el-button>
          <el-button type="danger" @click="submitData(3)" class="bt-fix"> 拒绝 </el-button>
        </div>

      </div>
    </el-form>

  </div>
</template>

<script>
  import {
    APPLY_FOR_TYPE,STORE_ORDER_AFTER_SALES_STATUS
  } from '@/constants/statusMap';
  export default {
    name: "orderAfterSales",
    props: {
      formData: {
        type: Object,
        required: true
      },
    },
    data() {
      return {
        STORE_ORDER_AFTER_SALES_STATUS,
        APPLY_FOR_TYPE,
        reason: '',
        ruleForm: {
          sku: {
            spec_values: '',
            image: '',

          },
          after_sales_no: '',
          apply_for_type: 0,
          refund_explain: '',
          refund_price: 0,
          phone: '',
          refund_express: '',
          refund_express_name: '',
          refund_express_prices: 0,
        },
      };
    },
    mounted() {
      this.getShipingOption();

    },
    methods: {
      isShowButtons(){
        //退款
        if(this.formData.apply_for_type == 2){
          return this.formData.status == 1
        }
        //退货退款
        if(this.formData.apply_for_type ==1){
          return this.formData.status == 1 || this.formData.status == 2
        }
        return false;

      },
      submitData(val) {
        let postData = {};
        if(val===3){
          if(this.formData.reason.length < 5){
            this.$message.error('拒绝售后必段填写拒绝的理由,并且不得少于5个字')
            return false;
          }
        }
        let msg='确定当前操作吗?';
        if(this.formData.apply_for_type ==2){
          msg='当前操作将退款给用户，继续吗?'
        }
        if(this.formData.apply_for_type ==1 && this.formData.status == 2){
          msg='当前操作将退款给用户，继续吗?'
        }
        this.$confirm(msg, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          postData.status = val;
          postData.reason = this.formData.reason;
          postData.id = this.formData.id;
          this.$emit('afterSales', postData)

        }).catch(() => {
          // 用户点击取消
          this.$message({
            type: 'info',
            message: '已取消操作'
          });
        });

      },

      getShipingOption() {
        this.$httpRequest.get('/order/info', {
          id: this.formData.oid
        }).then(result => {
          console.log('-------result--------', result)
          this.ruleForm = result.data

        }).catch(e => {
          this.$message.error(e.message)
        });
      }

    },
  };
</script>

<style scoped lang="scss">
  header {
    background-color: #fdf6ec;
    color: #e6a23c;
    padding: 30px;
    box-sizing: border-box;
  }

  .goods{
    padding: 30px;
    box-sizing: border-box;
    font-size: 16px;
  }

  .deliver-goods {}

  .demo-ruleForm{
    background-color: #fcfcfc;
  }

  .form-box {
    padding: 30px;
    box-sizing: border-box;
  }

  .order-no {
    font-size: 18px;
    padding-bottom: 10px;
  }

  .name {
    font-size: 16px;
    line-height: 24px;
  }

  .def-bt-box {
    padding: 30px;
  }

  .phone {
    padding-left: 20px;
  }

  .img-box{
    margin-top: 20px;
    display: flex;
    align-items:center;
  }
</style>
